{extend name='full'}

{block name="style"}
<style>
    form {
        width: calc(100% - 5px);
        height: calc(100% - 15px);
        margin-top: 15px;
    }
</style>
{/block}

{block name="content"}
<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form" lay-filter="category_add">
    <div class="layui-row layui-col-space10" style="padding: 0 15px;">
        {if !empty($account_show) }
        <div class="layui-col-md12">
            <label class="layui-form-label">{:lang("公司")}:</label>
            <div class="layui-input-block">
                <select name="account_id" class="layui-select" required>
                    <option value="">请选择</option>
                    {if !empty($account_arr) }
                    {foreach $account_arr as $account_id => $account_name }
                    <option value="{$account_id|default=''}" {if ($shop_account == $account_id) } selected  {/if}>{$account_name|default=''}</option>
                    {/foreach}
                    {/if}
                </select>
            </div>
        </div>
        {/if}
        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("父级分类")}:</label>
            <div class="layui-input-block">
                <input required value="{$parent_info.name|default=lang('根级分类')}" readonly class="layui-input">
                <input type="hidden" name="pid" value="{$pid}">
            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("分类名称")}:</label>
            <div class="layui-input-block">
                <input required name="name" value='' class="layui-input">
            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("分类编码")}:</label>
            <div class="layui-input-block">
                <input required name="code" value='' class="layui-input">
            </div>
        </div>
        <div class="layui-col-md12">
            <label class="layui-form-label">{:Lang("分类描述")}:</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="{:lang('分类描述')}" class="layui-textarea"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item text-center" style="margin-top: 30px;">
        {if empty($account_show) }
        <input type="hidden" name="account_id" value="{$shop_account|default=0}">
        {/if}
        <input type="hidden" id="pid" value="{$pid}|default=0">
        <button class="layui-btn" type='button' id="submit_btn">{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type='button' id="close_btn">{:lang('取消编辑')}</button>
    </div>
</form>
{/block}

{block name="script"}
<script>
    $(function() {
        let form = layui.form;

        $('#submit_btn').on('click', function() {
            let submit_data = form.val('category_add');
            if(!isNotEmpty(submit_data.name)) {
                layer.msg('{:lang("分类名称不能为空")}', {icon: 2});
                return false;
            }
            if(!isNotEmpty(submit_data.code)) {
                layer.msg('{:lang("分类编码不能为空")}', {icon: 2});
                return false;
            }
            httpRequest('{:url("add")}', submit_data, 'post', function(msg, res) {
                layer.msg('{:lang("保存成功")}', {icon: 1});
                setTimeout(function() {
                    let index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 1000);
            })
        });

        $('#close_btn').on('click', function() {
            layer.confirm('{:lang("确定要取消编辑吗")}', {
                btn: ['{:lang("确定")}', '{:lang("关闭")}'] //按钮
            }, function(){
                let index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        })

    })
</script>
{/block}